package org.base.sys.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.base.common.controller.BaseController;
import org.base.common.pojo.PageResult;
import org.base.sys.enums.LoginStatus;
import org.base.sys.pojo.SysLoginLog;
import org.base.sys.query.SysLoginLogQuery;
import org.base.sys.service.SysLoginLogService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 系统登录记录 前端控制器
 * </p>
 *
 * @author AutoGenerator
 * @since 2020-07-29
 */
@Api(value = "系统登录记录", tags = "系统登录记录")
@Validated
@AllArgsConstructor
@RestController
@RequestMapping("/sys-login-log")
@Slf4j
public class SysLoginLogController extends BaseController<SysLoginLog, SysLoginLogService> {

    /**
     * 添加
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加系统登录记录")
    public boolean add(@Valid @RequestBody SysLoginLog entity) {
        return service.save(entity);
    }

    /**
     * 根据id查询
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询系统登录记录")
    public SysLoginLog get(@PathVariable("id") Long id) {
        return service.getById(id);
    }

    /**
     * 更新
     */
    @PutMapping("/update")
    @ApiOperation(value = "根据id更新系统登录记录")
    public boolean update(@Valid @RequestBody SysLoginLog entity) {
        return service.updateById(entity);
    }

    /**
     * 添加或者保存
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "添加或者保存系统登录记录")
    public boolean saveOrUpdate(@Valid @RequestBody SysLoginLog entity) {
        return service.saveOrUpdate(entity);
    }

    /**
     * 查询
     */
    @GetMapping("/query")
    @ApiOperation(value = "列表查询系统登录记录")
    public List<SysLoginLog> query(SysLoginLogQuery query) {
        return service.getByQuery(query);
    }

    /**
     * 分页查询
     */
    @GetMapping("/pageQuery")
    @ApiOperation(value = "分页查询系统登录记录")
    public PageResult pageQuery(SysLoginLogQuery query) {
        return service.getByPageQuery(query);
    }


    @GetMapping("/loginStatus")
    public LoginStatus[] loginStatus() {
        return LoginStatus.values();
    }

}

